<?php
	require_once "../include/User.php";
	require_once "../include/Password.php";
	require_once "../include/backend/UserDb.php";
	require_once "../include/functions.php";
	
	session_start();
	
	if (!hasVal($_POST['given']) || !hasVal($_POST['surname']) 
	    || !hasVal($_POST['nationality']))
		header("Location: ../user.php?act=edit&err=empty&u=".$_SESSION['user']->name);
	
	$users = new UserDb();
	
	$_SESSION['user']->given = $_POST['given'];
	$_SESSION['user']->surname = $_POST['surname'];
	$_SESSION['user']->nationality = $_POST['nationality'];
	$_SESSION['user']->date_of_birth = $_POST['date_of_birth'];
	
	if (hasVal($_POST['pass1']) && hasVal($_POST['pass2'])) {
		if ($_POST['pass1'] == $_POST['pass2']) {
			$newpass = new Password($_POST['pass1']);
			$_SESSION['user']->pass = $newpass->gethash();
		}
		else
			header("Location: ../user.php?act=edit&err=pwmismatch&u=".$_SESSION['user']->name);
	}
	
	$users->set($_SESSION['user']);
	header("Location: ../user.php?u=".$_SESSION['user']->name);
?>
